﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cairo;
using System.Windows.Forms;

namespace FigureDraw
{
    public class SaveByCairo : FileDevice
    {
        ImageSurface i;
        Context c;

        public SaveByCairo(ImageSurface i, Context c)
        {
            this.i = i;
            this.c = c;
        }
        public override void drawLine(int x1, int y1, int x2, int y2)
        {
            this.c.MoveTo(x1, y1);
            this.c.LineTo(x2, y2);
            this.c.Stroke();
        }

        public override void drawRect(int x, int y, int width, int height)
        {
            this.c.Rectangle(x - width / 2, y - height / 2, width, height);
            this.c.Stroke();
        }

        public override void drawEllipse(int x, int y, int width, int height)
        {
            this.c.Save();
            int bankinhnho = width / 4;
            int bankinhlon = height / 4;
            this.c.Scale(bankinhnho, bankinhlon);
            if (bankinhnho != 0 && bankinhlon != 0)
            {
                this.c.Arc(x / bankinhnho, y / bankinhlon, 1, 0, 3.14 * 2);
                this.c.Stroke();
            }
            this.c.Restore();
        }
        public override void saveToFile(string fileName, string fileExtension)
        {
            switch (fileExtension)
            {
                case "PNG":
                    i.WriteToPng(fileName);
                    break;
                case "JPEG":
                    MessageBox.Show("Cannot find this function in Cairo! Not yet implemented...");
                    break;
                case "GIF":
                    MessageBox.Show("Cannot find this function in Cairo! Not yet implemented...");
                    break;
            }
        }
    }
}
